import React, { useEffect } from 'react';

import MyTable from '@/components/MyTable';
import EditMenu from '@/pages/System/components/editMenu';
import { findByDataMenuTreeList } from '@/services/sys/MenuService';
import { ProColumns } from '@ant-design/pro-components';
import { useRef } from 'react';
const PageView: React.FC = () => {
  // @ts-ignore
  const actionRef = useRef<ActionType>();
  /*  useEffect(() => {
      console.log('PageView');


      console.log(location);
  run()

    });*/
  // @ts-ignore
  // @ts-ignore
  const columns: ProColumns<API.MenuTreeInfo>[] = [
    {
      title: '图标',
      dataIndex: 'index',
      valueType: 'indexBorder',
    },
    {
      title: '图标',
      dataIndex: 'icon',
    },

    {
      title: '标题',
      dataIndex: 'name',
    },
    {
      title: '地址',
      dataIndex: 'routePath',
    },
    {
      title: '关键字',
      dataIndex: 'permsKey',
    },
    {
      title: '状态',
      dataIndex: 'type',

      valueType: 'select',
      valueEnum: {
        0: { text: '目录', status: 'Default' },
        1: {
          text: '菜单',
          status: 'Error',
        },
        2: {
          text: '按',
          status: 'Success',
          disabled: true,
        },
        3: {
          text: '其他',
          status: 'Processing',
        },
      },
    },
    {
      title: '操作',
      valueType: 'option',
      key: 'option',
      render: (text, record, _, action) => [
        <EditMenu
          text={'编辑'}
          row={record}
          onSuccess={() => {
            actionRef.current?.reload();
          }}
        />,
        <EditMenu
          text={'添加子'}
          row={{
            id: 0,
            parentId: record.id,
            name: '',
            path: '',
            permsKey: `${record.permsKey}:xxx`,
            icon: record.icon,
          }}
          onSuccess={() => {}}
        />,
      ],
    },
  ];
  useEffect(() => {}, []);
  return (
    <>
      <MyTable
        actionRef={actionRef}
        columns={columns}
        request={findByDataMenuTreeList}
        search={false}
        toolbar={() => [
          <EditMenu
            isCard={true}
            text={'新增菜单'}
            onSuccess={() => {
              actionRef.current?.reload();
            }}
          />,
        ]}
      ></MyTable>
    </>
  );
};
export default PageView;
